package sketch.view;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import javax.swing.WindowConstants;

public class NodeLabelsFrame extends javax.swing.JFrame {
	private JLabel title = null;
	private NodeLabelsPanel contentPane = null;
	private JPanel pageControlPane = null;
	private JButton cancelButton = null;
	private JButton okButton = null;
	
	private SketchPanel sPane=null;
	/**
	 * Auto-generated main method to display this JFrame
	 */

	public NodeLabelsFrame(SketchPanel sPane) {
		super();
		this.sPane=sPane;
		initGUI();
	}

	private void initGUI() {
		try {
			BorderLayout thisLayout = new BorderLayout();
			thisLayout.setHgap(5);
			thisLayout.setVgap(5);
			getContentPane().setLayout(thisLayout);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			
			getContentPane().add(getJLabelTitle(), BorderLayout.NORTH);
			getContentPane().add(getJPanelContent(), BorderLayout.CENTER);
			getContentPane().add(getJPanelPageControl(), BorderLayout.SOUTH);
			pack();
			this.setSize(261, 351);
			this.setLocation(400, 200);
			this.setAlwaysOnTop(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private NodeLabelsFrame getThis(){
		return this;
	}

	//get the title component
	private JLabel getJLabelTitle() {
		if (title == null) {
			title = new JLabel();
			BorderLayout titleLayout = new BorderLayout();
			title.setLayout(titleLayout);
			title.setText("component labels");
			title.setPreferredSize(new java.awt.Dimension(244, 32));
		}
		return title;
	}
	
	
	//get the contentPane component,including jScrollPane and controlPane
	private JPanel getJPanelContent(){
		if(contentPane==null){
			contentPane = new NodeLabelsPanel(getThis());
		}
		return contentPane;
	}
	
	//get the pageControlPanel component
	private JPanel getJPanelPageControl(){
		if(this.pageControlPane==null){
			pageControlPane = new JPanel();
			FlowLayout pageControlPaneLayout = new FlowLayout();
			pageControlPaneLayout.setHgap(0);
			pageControlPaneLayout.setVgap(0);
			pageControlPaneLayout.setAlignment(FlowLayout.RIGHT);
			pageControlPane.setLayout(pageControlPaneLayout);
			pageControlPane.setPreferredSize(new java.awt.Dimension(245, 34));
			{
				okButton = new JButton();
				pageControlPane.add(okButton);
				okButton.setText("OK");
				okButton.setPreferredSize(new java.awt.Dimension(70, 27));
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						getThis().dispose();
					}
				});
			}
			{
				cancelButton = new JButton();
				pageControlPane.add(cancelButton);
				cancelButton.setText("Cancel");
				cancelButton.setPreferredSize(new java.awt.Dimension(70, 27));
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						getSketchPanel().getTree().clear();
						getThis().dispose();
					}
				});
			}
		}
		return this.pageControlPane;
	}
	
	public SketchPanel getSketchPanel(){
		return sPane;
	}
	
}
